﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;
namespace Com.CMS263.DAO
{
   public  class ExtAttributeDAO
    {
       public void Add(ExtAttribute ea)
       {
           DBHelper.TransInsert(ea);
       }
       public void Modify(ExtAttribute ea)
       {
           DBHelper.TransSaveOrUpdate(ea);
       }
       public void Delete(int id)
       {
           DBHelper.TransDeleteByID("ExtAttribute", id);
       }
       /// <summary>
       /// 得到某类的全部扩展属性
       /// </summary>
       /// <param name="typeId">类别编号</param>
       /// <returns></returns>
       public IList<ExtAttribute> GetExtAttributeByTypeId(int typeId)
       {
          return  DBHelper.ExecuteHQL("from ExtAttribute where typeId="+typeId+" order by orderNum").List<ExtAttribute>();
       }
       /// <summary>
       /// 得到某类在后台显示的扩展属性
       /// </summary>
       /// <param name="typeId"></param>
       /// <returns></returns>
       public IList<ExtAttribute> GetShowInBackAttrByTypeId(int typeId)
       {
           return DBHelper.ExecuteHQL("from ExtAttribute where typeId=" + typeId + " and showInBack=1  order by orderNum").List<ExtAttribute>();
       }


       public bool Check(int typeId, string attrName)
       {
           return DBHelper.ExecuteHQL("from ExtAttribute where typeId=" + typeId + " and  attrName='"+attrName+"'").List().Count>0;
       }
    }
}
